const { count } = require("console");
var dgram = require("dgram");

var socket = dgram.createSocket("udp4");

socket.on("error", function (err) {

  console.log("socket error:n" + err.stack);

  //socket.close();

});

socket.on("message", function (msg, rinfo) {

  console.log("socket got: " + msg + " from " +rinfo.address + ":" + rinfo.port);

});


socket.on("listening", function () {

  var address = socket.address();

  console.log("socket listening " + address.address + ":" + address.port);
});

socket.bind(4532,function () {

  socket.setBroadcast(true);

});

var str="ding";
var message = new Buffer.alloc(str.length,"ding");

socket.send(message, 0, message.length, 3001, '192.168.3.16', function(err, bytes) {

});